﻿
namespace Bettzueche.RLLibrary.Types
{
    /// <summary>
    /// Tupel (AktionsNr, FeatureNr).
    /// <para>
    /// Dient (der QEFunktion) zum Indizieren von WETupeln (Maßnahme zur Speicheroptimierung).
    /// </para>
    /// </summary>
    public struct AFTupel
    {
        /// <summary>
        /// Die Aktions-Nummer
        /// </summary>
        public int ActionNr;

        /// <summary>
        /// Die Merkmalsnummer
        /// </summary>
        public int FeatureNr;

        /// <summary>
        /// Initializes a new instance of the <see cref="AFTupel"/> struct.
        /// </summary>
        /// <param name="action">The action id</param>
        /// <param name="feature">The feature id</param>
        public AFTupel(int action, int feature) {
            ActionNr = action;
            FeatureNr = feature;
        }

        #region objec overrides

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode() {
            int hash = 23;
            hash = hash * 37 + ActionNr;
            hash = hash * 37 + FeatureNr;
            return hash;
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj) {
            if (obj == null)
                return false;
            if (obj is AFTupel) {
                var other = (AFTupel)obj;
                return this.Equals(other);
            }
            return false;
        }

        /// <summary>
        /// Determines whether the specified <see cref="AFTupel" />, is equal to this instance.
        /// </summary>
        /// <param name="other">The <see cref="AFTupel" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="AFTupel" />'s fields are equal to this instance' fields; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(AFTupel other) {
            return (ActionNr == other.ActionNr) && (FeatureNr == other.FeatureNr);
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString() {
            return "AFTupel(" + ActionNr + "," + FeatureNr + ")";
        }

        #endregion
    }
}
